package com.eqdd.yiqidian.ui.mine.pizhun;

import android.os.Bundle;
import android.view.View;

import com.eqdd.yiqidian.adapter.slimadapter.SlimAdapterEx;
import com.eqdd.yiqidian.base.AppConstent;
import com.eqdd.yiqidian.base.BaseInfoActivity;
import com.eqdd.yiqidian.base.Config;
import com.eqdd.yiqidian.bean.rebuild.CarPaperInfoBean;
import com.eqdd.yiqidian.bean.rebuild.slimedit.SlimEditBean;
import com.eqdd.yiqidian.bean.rebuild.slimedit.SlimEditEnterBean;
import com.eqdd.yiqidian.bean.rebuild.slimedit.SlimEditHintBean;
import com.eqdd.yiqidian.http.DialogCallBack;
import com.eqdd.yiqidian.http.HttpConfig;
import com.eqdd.yiqidian.http.HttpResult;
import com.eqdd.yiqidian.ui.gongneng.car.CarInfoActivity;
import com.eqdd.yiqidian.ui.mine.UserCardActivity;
import com.eqdd.yiqidian.ui.mine.renwu.TextActivity;
import com.eqdd.yiqidian.utils.ToastUtil;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;

public class CarPaperInfoActivity extends BaseInfoActivity {
    private CarPaperInfoBean items;
    private Bundle bundle;

    @Override
    public void initTitle() {
        initTopTitleBar(View.VISIBLE, "用车详情");

    }

    @Override
    protected void checkPost() {
        OkGo.<HttpResult>post(HttpConfig.BASE_URL + HttpConfig.CAR_CHECK)
                .params("userGuid", AppConstent.user.getGuid())
                .params("applyId", items.getId())
                .params("message", dealText(dataBinding.etRemark.getText().toString()))
                .params("option", dataBinding.rbAgree.isChecked() ? 1 : -1)
                .execute(new DialogCallBack<HttpResult>(this) {
                    @Override
                    public void onSuccess(Response<HttpResult> response) {
                        HttpResult httpResult = response.body();
                        ToastUtil.showShort(httpResult.getMsg());
                        if (httpResult.getStatus() == 200) {
                            setResult(Config.DELETE);
                            finish();
                        }
                    }
                });
    }

    @Override
    protected void itemClick(int position) {
        switch (slimAdapterEx.getDataItem(position).getPosition()) {
            case 0:
                bundle = new Bundle();
                bundle.putString(Config.GUID, items.getApplyer());
                startActivity(UserCardActivity.class, bundle);
                break;
            case 1:
                bundle = new Bundle();
                bundle.putInt(Config.ID, items.getVehicleId());
                startActivity(CarInfoActivity.class, bundle);
                break;
            case 8:
                bundle = new Bundle();
                bundle.putString(Config.TITLE, "申请事由");
                bundle.putString(Config.CONTENT, items.getTheReason());
                startActivity(TextActivity.class, bundle);
                break;
        }
    }


    @Override
    public void setView() {
        OkGo.<HttpResult<CarPaperInfoBean>>post(HttpConfig.BASE_URL + HttpConfig.PAPER_CAR_INFO)
                .params("applicationId", id)
                .params("userGuid", AppConstent.user.getGuid())
                .params("comid", AppConstent.user.getCompanyId())
                .execute(new DialogCallBack<HttpResult<CarPaperInfoBean>>(this) {
                    @Override
                    public void onSuccess(Response<HttpResult<CarPaperInfoBean>> response) {
                        HttpResult<CarPaperInfoBean> httpResult = response.body();
                        ToastUtil.showShort(httpResult.getMsg());
                        if (httpResult.getStatus() == 200) {
                            items = httpResult.getItems();
                            if (who != 0) {
                                data.add(new SlimEditEnterBean("申请人", items.getApplyerName(), 0, ""));
                            }
                            data.add(new SlimEditEnterBean("车辆", items.getPlateNumber(), 1, ""));
                            data.add(new SlimEditHintBean("开始时间", items.getStartTime(), 2));
                            data.add(new SlimEditHintBean("结束时间", items.getEndTime(), 3));
                            data.add(new SlimEditHintBean("出发地", items.getOrigin(), 4));
                            data.add(new SlimEditHintBean("目的地", items.getDestination(), 5));
                            data.add(new SlimEditHintBean("司机姓名", items.getTheDriverName(), 6));
                            data.add(new SlimEditHintBean("坐车人数", items.getPersonCount() + "个人", 7));
                            data.add(new SlimEditEnterBean("申请事由", items.getTheReason(), 8, ""));
                            data.add(new SlimEditHintBean("关联客户", items.getTheCustomer(), 9));
                            data.add(new SlimEditHintBean("关联项目", items.getTheProject(), 10));
                            if (who == 0 && status == 0) {
                                if (items.getUpdater() == null) {
                                    data.add(new SlimEditHintBean("部门领导", "审核中", 11));
                                } else {
                                    data.add(new SlimEditHintBean("部门领导", "审核通过", 11));
                                    data.add(new SlimEditHintBean("车辆管理员", "审核中", 12));
                                }
                            }
                            slimAdapterEx.updateData(data);
                            if (who >= 1 && status == 0) {
                                dataBinding.llDownRoot.setVisibility(View.VISIBLE);
                            }
                        }
                    }
                });
    }


}
